package com.atguigu4.search_sort.exer1;

/**
 * @author lhl
 * @date 2025/3/31 13:46
 */
public class ArrayExer01_1 {
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4,5};

        //扩容1倍容量
        //方式1：int[] newArr = new int[arr.length * 2];
        //方式2
        int[] newArr = new int[arr.length << 1];

        //将原有数组的数据添加到新数组中
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i];
        }

        //加入剩下的值
        newArr[arr.length] = 10;
        newArr[arr.length + 1] = 20;
        newArr[arr.length + 2] = 30;

        //将新的数组的地址赋值给原有的数组
        arr = newArr;
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+"\t");
        }
    }
}
